package main

import (
	"fmt"
	"github.com/shopspring/decimal"
	"strconv"
	"strings"
)

func main() {
	fmt.Println(PointsToYuan(160431862))
}

//价格精度计算,返回元
func PointsToYuan(points uint32) string {
	consumeAmount := strconv.FormatFloat(float64(points)/1000, 'f', -1, 64) //bitSize=64时正确，返回 1604318.62, bitSize=32时 返回 1604318.6

	fmt.Println(consumeAmount)

	return makePrice(consumeAmount, 2)
}

// 封装金额
func makePrice(consumeAmount string, num int32) string {
	price, _ := decimal.NewFromString(consumeAmount)
	consumeAmount = price.Truncate(num).String()
	consumeAmount = strings.TrimSuffix(consumeAmount, ".0")
	consumeAmount = strings.TrimSuffix(consumeAmount, ".00")

	return consumeAmount
}